// 首页
// https://a.ctfs888.com/

// 接单
// https://sdapi.ctfs888.com/buyer/account/order/getTaskListByBuyer

// 登录
// https://a.ctfs888.com/user


// 获取tokeN
function getAndroidToken() {
    let token = localStorage.getItem("token").replace(/^"|"$/g, '');
    let client = localStorage.getItem("client").replace(/^"|"$/g, '');
    let token_client = token +","+ client;
    return token_client
}
getAndroidToken()


// 打开页面
function openHome(){
    let token = Android.getMap("token")
    if(!token){
        return
    }
    let l = token.split(",")
    localStorage.setItem("token",l[0] || "")
    localStorage.setItem("client",l[1] || "")
}
openHome()



// 请求数据
function getParameterHandler() {
    let token = parameter.getMap("token")
    if(!token){
        return
    }
    let l = token.split(",")
    let headers = {}
    let body = {
        "token": l[0] || "",
        "client": l[1] || "",
        "params": {
            "page": 1,
            "size": 10,
            "platform": "全部",
            "state": "已接单",
            "client_timestamps": new Date().getTime()
        }
    }
    let url = parameter.getMap("url")
    return {
        mediaType: "json",
        requestType: "POST",
        url: url,
        headers: JSON.stringify(headers),
        body: JSON.stringify(body)
    }
}
getParameterHandler()


// 处理返回数据
function getResponse() {
    let res = response.getMap("res")
    let code = "300"
    let message = "接单中"

    res = JSON.parse(res)
    if (res["code"] == 200 && res["data"]["totalElements"] > 0) {
        code = "200"
        message = "接单成功，请尽快完成"
    } else if (res["code"] == 200 && res["data"]["totalElements"] <= 0) {
        code = "500"
        message = "接单中"
    } else {
        code = "300"
        message = res["message"]
    }

    return {
        code: code,
        message: message,
        dataKey: "",
        dataValue: ""
    }
}
getResponse()
